﻿@model CID.Web.Models.Audit.ReleaseDeploymentLogListViewModel

@{
    ViewBag.Title = "Deployment Logs' Index";
    AjaxOptions ajaxOptions = new AjaxOptions(){
        Url = Url.Action("Index"),
        LoadingElementId = "loadingPanel",
        UpdateTargetId = "dataPanel"
    };
}

<h2>Deployment Logs</h2>

@using (Ajax.BeginForm(ajaxOptions))
{
<div>
    <div>
        <label>Release</label>
        @Html.DropDownList("releaseId", Model.FilterReleases.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Name }), "Filter...")
    </div>
    <div>
        <label>Environment</label>
        @Html.DropDownList("environmentId", Model.FilterEnvironments.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Name }), "Filter...")
    </div>
    <div>
        <label>Responsible</label>
        @Html.DropDownList("responsibleId", Model.FilterResponsibles.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Name }), "Filter...")
    </div>
    <div>
        <label>Status</label>
        @Html.DropDownList("status", Model.FilterStatus.Select(x => new SelectListItem() { Value = Convert.ToInt32(x).ToString(), Text = x.ToString() }), "Filter...")
    </div>
    <div>
        <input type="button" value="Clear" id="ClearFilters" />
        <input type="submit" value="Apply" />
    </div>
</div>
}

<div id="loadingPanel" style="display:none; color:Red; font-weight: bold">
    <p>Loading Data...</p>
</div>
<div id="dataPanel">
    <table>
        <tr>
            <th>
                Release
            </th>
            <th>
                Environment
            </th>
            <th>
                Status
            </th>
            <th>
                Started on
            </th>
            <th>
                Ended on
            </th>
            <th>
                Responsible
            </th>
            <th></th>
        </tr>

    @foreach (var item in Model.ReleaseDeploymentLogs) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Release.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Environment.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Status)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.StartTimestamp)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.EndTimestamp)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Responsible.Name)
            </td>
            <td>
                @Html.ActionLink("Details", "Details", new { id = item.Id })
            </td>
        </tr>
    }

    </table>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("#ClearFilters").click(function () {
            $("select").val("0");
        });
    });
</script>